package servlet;

import dao.DishesDao;
import dao.impl.DishesDaoImpl;
import pojo.Dishes;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;


@WebServlet(urlPatterns = "/dishesServlet.do")
public class dishesServlet extends HttpServlet {
    private DishesDao dishesDao=new DishesDaoImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String bus_no = req.getParameter("bus_no");
        getServletContext().setAttribute("bus_no",bus_no);
        System.out.println(bus_no);
        List<Dishes> dishesList = dishesDao.findBusDishes(bus_no);
        req.setAttribute("dishes",dishesList);
        getServletContext().setAttribute("dishes",dishesList);

        HttpSession session=req.getSession();
        session.setAttribute("dishes",dishesList);

        for (Dishes dish:dishesList){
            System.out.println(dish.toString());
        }
        req.getRequestDispatcher("dish_View.jsp").forward(req,resp);
    }
}
